﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 图书管理系统.Utils
{
    internal class Camera
    {
        public static AForge.Video.DirectShow.FilterInfoCollection videoDevices =
            new AForge.Video.DirectShow.FilterInfoCollection(AForge.Video.DirectShow.FilterCategory.VideoInputDevice);
        public static AForge.Video.DirectShow.VideoCaptureDevice videoSource;
        public static int DeviceIndex = 0;
        public static int PICIndex = 0;

        public static AForge.Video.DirectShow.VideoCaptureDevice getvideoSource()
        {

            //连接摄像头。
            videoSource = new AForge.Video.DirectShow.VideoCaptureDevice(videoDevices[DeviceIndex].MonikerString);
            videoSource.VideoResolution = videoSource.VideoCapabilities[DeviceIndex];
            // 枚举所有摄像头支持的像素，设置拍照为1920*1080
            foreach (AForge.Video.DirectShow.VideoCapabilities capab in videoSource.VideoCapabilities)
            {
                if (PICIndex == 0)
                {
                    if (capab.FrameSize.Width == 1920 && capab.FrameSize.Height == 1080)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                    if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                }
                else
                {
                    if (capab.FrameSize.Width == 1280 && capab.FrameSize.Height == 720)
                    {
                        videoSource.VideoResolution = capab;
                        break;
                    }
                }
            }
            return videoSource;
        }


    }
}
